/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.smn.jsf;

import com.smn.domain.MyUser;
import com.smn.domain.Share;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.ejb.EJB;

/**
 *
 * @author Ant Ongun Kefeli
 */
@ManagedBean(name = "mySharesDataListBean")
@SessionScoped
public class MySharesDataListBean implements Serializable {

    @ManagedProperty(value = "#{myUserController}")
    private MyUserController myUserController;
    @EJB
    private com.smn.dao.ShareFacade shareFacade;
    @EJB
    private com.smn.dao.MyUserFacade myUserFacade;

    /** Creates a new instance of MySharesDataListBean */
    public MySharesDataListBean() {
    }

    public List<Share> getMySharesList() {
        List<Share> myShares = new ArrayList<Share>();
        try {

            myShares = shareFacade.findSharesById(myUserController.getSelected());
            if (myShares != null && myShares.size() > 0) {//get shares
                List<MyUser> invitedUsers, acceptedUsers;
                for (int i = 0; i < myShares.size(); i++) {
                    invitedUsers = myUserFacade.findUsersForShare(myShares.get(i));
                    myShares.get(i).setInvitedUsers(invitedUsers);
                    acceptedUsers = myUserFacade.findAcceptedUsersForShare(myShares.get(i));
                    myShares.get(i).setAcceptedUsers(acceptedUsers);
                }
                return myShares;
            }
          
            return myShares;
        } catch (Exception ex) {
            System.out.println(ex.getLocalizedMessage());
            return null;
        }

    }

    public void setMyUserController(MyUserController myUserController) {
        this.myUserController = myUserController;
    }
}
